import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../resource/ImagesConst";
import { Cache } from "../../cache/Cache";
import { ECountryPosition } from "../../../../Message/Game/ECountryPosition";
import { CountryPositionItem } from "./CountryPositionItem";
import { GSprite } from "../../../../com/mui/controls/GSprite";
import { BitmapNumberPanel } from "./BitmapNumberPanel";
import { _ECountryPositionKing } from "../../../../ECountryPosition/_ECountryPositionKing";
import { _ECountryPositionQueen } from "../../../../ECountryPosition/_ECountryPositionQueen";
import { _ECountryPositionMarquis1 } from "../../../../ECountryPosition/_ECountryPositionMarquis1";
import { _ECountryPositionMarquis2 } from "../../../../ECountryPosition/_ECountryPositionMarquis2";
import { _ECountryPositionGeneral } from "../../../../ECountryPosition/_ECountryPositionGeneral";
import { _ECountryPositionChancellor } from "../../../../ECountryPosition/_ECountryPositionChancellor";
import { _ECountryPositionOfficer } from "../../../../ECountryPosition/_ECountryPositionOfficer";
import { _ECountryPositionMinister } from "../../../../ECountryPosition/_ECountryPositionMinister";
//class CountryPositionInfoPanel
    
    export  class CountryPositionInfoPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._positionItemMap = new Map<any, any> /* flash.utils.Dictionary */();
            this.createPositionItem();
            return;
        }

        /* internal  */createPositionItem(): void
        {
            var loc2=null;
            var loc3=null;
            addChild(new GImageBitmap(ImagesConst.countryPositionBg, 0, 0));
            var loc1=Cache.instance.country.selfCountryInfo;
            this._positionArr = [{"pos": _ECountryPositionKing, "x": 280, "y": 5, "oper":"left"}, {"pos": _ECountryPositionQueen, "x": 370, "y": 5, "oper":"right"}, {"pos": _ECountryPositionMarquis1, "x": 210, "y": 40, "oper":"left"}, {"pos": _ECountryPositionMarquis2, "x": 440, "y": 40, "oper":"right"}, {"pos": _ECountryPositionGeneral, "x": 150, "y": 95, "oper":"left"}, {"pos": _ECountryPositionChancellor, "x": 500, "y": 95, "oper":"right"}, {"pos": _ECountryPositionOfficer, "x": 80, "y": 180, "oper":"left"}, {"pos": _ECountryPositionMinister, "x": 560, "y": 170, "oper":"right"}];
            var loc4=0;
            while (loc4 < this._positionArr.length) 
            {
                loc3 = this._positionArr[loc4];
                loc2 = new CountryPositionItem(loc3.pos, loc1, loc3.oper);
                loc2.x = loc3.x;
                loc2.y = loc3.y;
                if (loc3.pos != ECountryPosition._ECountryPositionQueen) 
                {
                    addChild(loc2);
                }
                else 
                {
                    addChildAt(loc2, 1);
                }
                this._positionItemMap[loc3.pos] = loc2;
                ++loc4;
            }
            return;
        }

        public updateOfficerInfo(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=false;
            var loc4=0;
            var loc5=0;
            var loc6=this._positionItemMap;
            for(loc2 of loc6) 
            {
                loc3 = false;
                loc4 = 0;
                while (loc4 < arg1.length) 
                {
                    loc1 = arg1[loc4];
                    if (loc1 && loc1.position == loc2.position) 
                    {
                        loc2.updateOfficerInfo(loc1);
                        loc3 = true;
                        break;
                    }
                    ++loc4;
                }
                if (loc3) 
                {
                    continue;
                }
                loc2.updateOfficerInfo(null);
            }
            return;
        }

        public updateServiceCombat(): void
        {
            var loc1=0;
            if (Cache.instance.role.curWorldLevel) 
            {
                if (this._combatSp == null) 
                {
                    this._combatSp = new GSprite();
                    addChildAt(this._combatSp, 1);
                }
                if (this._serviceCombatBmp == null) 
                {
                    this._serviceCombatBmp = new GImageBitmap(ImagesConst.serviceCombat, 200, 350);
                    this._combatSp.addChild(this._serviceCombatBmp);
                }
                loc1 = int(Cache.instance.country.serviceCombat);
                if (this._numberPanel == null) 
                {
                    this._numberPanel = new BitmapNumberPanel();
                    this._numberPanel.x = 320;
                    this._numberPanel.y = 363;
                    this._combatSp.addChild(this._numberPanel);
                }
                this._numberPanel.setNumber(loc1);
                if (this._unitBmp == null) 
                {
                    this._unitBmp = new GImageBitmap(ImagesConst.unitBmp, 600, 363);
                    this._combatSp.addChild(this._unitBmp);
                }
                if (this._numberPanel.width > 0) 
                {
                    this._unitBmp.x = this._numberPanel.x + this._numberPanel.width;
                }
            }
            return;
        }

        /* internal */ /* var */_positionArr: Array<any>;

        /* internal */ /* var */_positionItemMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_combatSp: GSprite;

        /* internal */ /* var */_serviceCombatBmp: GImageBitmap;

        /* internal */ /* var */_numberPanel: BitmapNumberPanel;

        /* internal */ /* var */_unitBmp: GImageBitmap;
    }
